package com.md.model.excel;

import lombok.Data;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;

import static com.md.util.ExcelUtil.getBorderCtColor;

/**
 * @author 刘骄阳
 * 2024-05-14 23:42
 */
@Data
public class BorderGroup {


  /**
   * 上边框样式
   */
  private BorderStyleInfo top;
  /**
   * 下边框样式
   */
  private BorderStyleInfo bottom;
  /**
   * 左边框样式
   */
  private BorderStyleInfo left;
  /**
   * 有边框样式
   */
  private BorderStyleInfo right;

  public static BorderGroup readBorder(final XSSFCellStyle cellStyle,
                                       final StylesTable stylesTable) {
    BorderGroup borderGroup = new BorderGroup();
    borderGroup.setTop(BorderStyleInfo.of(cellStyle.getBorderTop(),
      ExcelColorInfo.getColorInfo(getBorderCtColor(cellStyle.getTopBorderXSSFColor()), stylesTable)));
    borderGroup.setBottom(BorderStyleInfo.of(cellStyle.getBorderBottom(),
      ExcelColorInfo.getColorInfo(getBorderCtColor(cellStyle.getBottomBorderXSSFColor()), stylesTable)));
    borderGroup.setLeft(BorderStyleInfo.of(cellStyle.getBorderLeft(),
      ExcelColorInfo.getColorInfo(getBorderCtColor(cellStyle.getLeftBorderXSSFColor()), stylesTable)));
    borderGroup.setRight(BorderStyleInfo.of(cellStyle.getBorderRight(),
      ExcelColorInfo.getColorInfo(getBorderCtColor(cellStyle.getRightBorderXSSFColor()), stylesTable)));
    return borderGroup;
  }

}
